package com.example.myapplication.urbansubway;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.Config.RunOnUiThreadTool;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.RouteclassificationBean;
import com.example.myapplication.ShuJu.RouteoverviewBean;
import com.example.myapplication.apter.RouteclassificationApter;

public class UrbansubwayActivity extends AppCompatActivity {

    private ImageView img;
    private RecyclerView routelist;
    private LinearLayout routemap;
    private ImageView imgmore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_urbansubway);
        initview();
        //返回
        but_bloak();
        //路线分类
        routeclassification();
        //路线总览
        routeoverview();
        //总览图页面
        overviewmappage();

    }

    private void overviewmappage() {
        imgmore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UrbansubwayActivity.this,OverviewmappageActivity.class);
                UrbansubwayActivity.this.startActivity(intent);
            }
        });
    }

    private void routeoverview() {
        routemap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OKHttpTool.doNetRequest("prod-api/api/metro/city",
                        OKHttpTool.GET,
                        RouteoverviewBean.class,
                        new OKHttpTool.NetCallback() {
                            @Override
                            public void onSuccess(Object obj) {
                                RunOnUiThreadTool.run(UrbansubwayActivity.this, new RunOnUiThreadTool.RunCallback() {
                                    @Override
                                    public void set() {
                                        RouteoverviewBean routeoverviewBean = (RouteoverviewBean)obj;

                                        if(routeoverviewBean.getCode()==200){

                                            Intent intent = new Intent(UrbansubwayActivity.this,RouteoverviewActivity.class);
                                            intent.putExtra(Commom.ROUTEOVERVIEWBEANID,routeoverviewBean.getData().getImgUrl());
                                            UrbansubwayActivity.this.startActivity(intent);
                                        }
                                    }
                                });
                            }

                            @Override
                            public void onFailure(String msg) {

                            }
                        });
            }
        });
    }

    private void routeclassification() {
        OKHttpTool.doNetRequest("prod-api/api/metro/list?currentName=建国门",
                OKHttpTool.GET,
                RouteclassificationBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        RunOnUiThreadTool.run(UrbansubwayActivity.this, new RunOnUiThreadTool.RunCallback() {
                            @Override
                            public void set() {
                                RouteclassificationBean routeclassificationBean = (RouteclassificationBean)obj;
                                if(routeclassificationBean.getCode()==200){

                                    routelist.setAdapter(new RouteclassificationApter(UrbansubwayActivity.this,routeclassificationBean.getData()));
                                    routelist.setLayoutManager(new LinearLayoutManager(UrbansubwayActivity.this));
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UrbansubwayActivity.this.finish();
            }
        });
    }

    private void initview() {
        img = findViewById(R.id.img);
        routelist = findViewById(R.id.routelist);
        routemap = findViewById(R.id.routemap);
        imgmore = findViewById(R.id.imgmore);
    }
}